import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_plugin_league_notice/src/helper/constants.dart';
import 'package:flutter_plugin_league_notice/src/helper/get_builder_ids.dart';
import 'package:flutter_plugin_league_notice/src/page/wait_done_detail_list/wait_done_detail_list_controller.dart';
import 'package:flutter_plugin_league_notice/src/widgets/wait_done_category_item.dart';
import 'package:flutter_plugin_version/flutter_plugin_version.dart';

///
/// 待办 消息详情列表Page
///
class WaitDoneDetailListPage extends StatelessWidget {
  final String? title;

  const WaitDoneDetailListPage({
    super.key,
    this.title,
  });

  @override
  Widget build(BuildContext context) {
    WaitDoneDetailListController controller = Get.put(WaitDoneDetailListController());

    return Scaffold(
      backgroundColor: const Color(0x70ecf2f1),
      appBar: AppBar(
        centerTitle: true,
        title: Text(
          title ?? '消息',
          style: TextStyle(
            fontSize: 20.sp,
            fontWeight: FontWeight.bold,
          ),
        ),
      ),
      body: Column(
        children: [
          /// 列表
          Expanded(
            child: GetBuilder<WaitDoneDetailListController>(
              id: NoticeBuilderIds.id_wait_done_detail_list,
              builder: (controller) {
                var list = controller.newsCategroies;

                if (list == null) {
                  return const SizedBox.shrink();
                } else {
                  if (list.isEmpty) {
                    return const EmptyView(msg: '暂无信息');
                  } else {
                    return EasyRefresh(
                      clipBehavior: Clip.none,
                      onLoad: controller.loadMore ? () => controller.handlerOnRefresh() : null,
                      footer: const AiRefreshFooterBuilder(),
                      child: Padding(
                        padding: const EdgeInsets.symmetric(vertical: NoticeConstants.kPadding),
                        child: CustomScrollView(
                          reverse: true,
                          shrinkWrap: true,
                          clipBehavior: Clip.none,
                          slivers: [
                            SliverList(
                              delegate: SliverChildBuilderDelegate(
                                (context, index) => WaitDoneCategoryItem(categroyModel: list[index]),
                                childCount: list.length,
                              ),
                            ),
                          ],
                        ),
                      ),
                    );
                  }
                }
              },
            ),
          ),

          /// 进入应用
          if (controller.appType != null)
            Container(
              color: Colors.white,
              width: double.infinity,
              padding: const EdgeInsets.only(
                left: NoticeConstants.kPadding,
                right: NoticeConstants.kPadding,
                top: NoticeConstants.kPadding * 0.5,
                bottom: NoticeConstants.kPadding,
              ),
              child: TextButton(
                onPressed: () => controller.handlerEnterAppEvent(),
                style: TextButton.styleFrom(
                  backgroundColor: Colors.white,
                  foregroundColor: const Color(0xff07B18C),
                  textStyle: TextStyle(fontSize: 18.sp, fontWeight: FontWeight.bold),
                  shape: RoundedRectangleBorder(
                    side: const BorderSide(color: Color(0xff07B18C), width: 1),
                    borderRadius: BorderRadius.circular(8.r),
                  ),
                ),
                child: const Text('进入应用'),
              ),
            )
          else
            const SizedBox(height: NoticeConstants.kPadding * 2),
        ],
      ),
    );
  }
}
